# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-optparse
_pkgname=optparse
pkgver=1.4
pkgrel=1
pkgdesc="Parse and process command-line options"
url="https://github.com/gvvaughan/optparse"
arch="noarch"
license="MIT"
source="$pkgname-$pkgver.tar.gz::https://github.com/gvvaughan/$_pkgname/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
options="!check"  # tests requires additional dependencies

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local lmod_dir="$subpkgdir/usr/share/lua/$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-1"

	cd "$builddir"
	mkdir -p "$lmod_dir"
	cp -r "$builddir"/lib/* "$lmod_dir"/

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="8e3d95e02bba38551fbba04414d142eaf5b22ffd55c7d2225773e99442e14f894ca0bd6e4c00f47f33335cb54fbea8ff8c5f0ceef170b9c77b9a8b085838bc95  lua-optparse-1.4.tar.gz"
